package featureExtractors;

import org.opencv.core.Mat;


import pdi.OpenCvCaller;
import pdi.core.Image;


public class RawPixelsFeature extends AbstractFeatureExtraction {

	@Override
	public double[] extractFeature(Image candidate) {
		Image aux = candidate.clone();
		
		if(aux.getMatrixRepresentation() == null)
			throw new IllegalArgumentException("The image matrix representation it is necessary");
		
		if(aux.getMatrixRepresentation().channels() > 2)
			  aux = OpenCvCaller.getInstance().convertToGrayScale(aux);
		
		Mat matrix = aux.getMatrixRepresentation();
		double[] featureVector = new double[matrix.width() * matrix.height()];
		
		int idx = 0;
		for (int x = 0; x < matrix.width(); x++) {
			for (int y = 0; y < matrix.height(); y++) {
				featureVector[idx] = matrix.get(y, x)[0];
				idx++;
			}
		}		
		return featureVector;
	}

}
